package com.xinyi.reactivemvvmkt.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.xinyi.reactivemvvmkt.model.NeteaseCommentModel
import com.xinyi.reactivemvvmkt.model.Resource
import com.xinyi.reactivemvvmkt.model.request.NeteaseCommentRequest
import com.xinyi.reactivemvvmkt.sources.repository.MainRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
 * @author 杨耿雷
 * @date 2024/9/24 21:33
 * @description 主页ViewModel
 */
@HiltViewModel
class MainViewModel @Inject constructor(private val mMainRepository: MainRepository) : ViewModel() {

    /**
     * 网易云评论
     */
    private val _mNeteaseComment: MutableLiveData<Resource<NeteaseCommentModel>> =
        MutableLiveData<Resource<NeteaseCommentModel>>()
    val mNeteaseComment: MutableLiveData<Resource<NeteaseCommentModel>> get() = _mNeteaseComment

    /**
     * 请求网易云评论
     */
    fun requestNeteaseComment(request: NeteaseCommentRequest) = viewModelScope.launch {
        mMainRepository.getNeteaseComment(request).collect {
            _mNeteaseComment.value = it
        }
    }
}